/*
 * Plane.java
 *
 * Created on September 3, 2007, 5:55 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Raytracing.Geometry;
import Raytracing.Ray;
import processing.core.*;

/**
 *
 * @author Matt
 */
public class Plane {
    
    PVector origin;
    PVector normal;
        
    /** Creates a new instance of Plane */
    public Plane(float ox, float oy, float oz, float nx, float ny, float nz) {
    
        origin = new PVector(ox,oy,oz);
        normal = new PVector(nx,ny,nz);
        
        //I don' trust people
        normal.normalize();
    }
    
    public void draw(PGraphics g){
        g.beginShape();
            g.vertex(origin.x, origin.y, origin.z);
            g.vertex(normal.x, normal.y, normal.z);
        g.endShape();
    }
    
    public boolean intersect(Ray state){
    
        float dn = state.direction.dot(normal);
        if (dn == 0) return false;
        state.distance = (((origin.x - state.origin.x) * normal.x) + ((origin.y - state.origin.y) * normal.y) + ((origin.z - state.origin.z) * normal.z)) / dn;
        if (state.distance > state.minDist || state.distance < state.maxDist) return true;
        else return false;
    }    
    
}
